layui.define(
  ["laydate", "table", "laypage", "form", "element"],
  function (exports) {
    var proID = jTools.getQuery("proID"),
      proType = jTools.getQuery("proType"),
      element = layui.element;
    element.init();
    renderProduct();
    //渲染展示文件的html页面
    function renderProductHtml(data, project, proType, proID) {
      $(".layui-breadcrumb").html(
        '<a href="projectManagement.html">' + project.name + "</a>"
      );
      var str = ""; //用来存储html内容
      for (let key in data) {
        str += `<li class="nextLevelFile" data-key="${key}" data-name="${data[key]}"><a title="${data[key]}"><img src="../../layuiadmin/images/filesIcon.png"/><p class="changename">${data[key]}</p></a></li>`;
      }
      $(".projectManagementList #projectManagementListCon").html(str);
      $(".nextLevelFile").on("click", function () {
        var cate = $(this).attr("data-key");
        var projectNameNext = $(this).attr("data-name");
        layui.data("proID", {
          key: "key",
          value: proID,
        });
        location.href =
          "projectManagementNextTN.html?cate=" +
          cate +
          "&proType=" +
          proType +
          "&projectName=" +
          project.name +
          "&projectNameNext=" +
          projectNameNext;
      });
    }

    //同步加载文件的数据
    function renderProduct() {
      $.ajax({
        async: false,
        url: base_url + "/projectManage/queryProCateByProID",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({ proID: proID, proType: proType }),
        dataType: "json",
        success: function (data) {
          var proID = data.data.proID;
          var nextLevelFileData = data.data.folder;
          var project = data.data.project;
          var proType = data.data.proType;
          renderProductHtml(nextLevelFileData, project, proType, proID);
        },
      });
    }
    $(".backPreviousPage").on("click", function () {
      window.history.back(-1);
    });

    exports("projectManagementNext", {});
  }
);
